/*
 * @Author: yangzonglong
 * @Date: 2021-02-22 13:49:17
 * @version: v1.0.0
 * @Descripttion: 类型声明
 * @LastEditors: yangzonglong
 * @LastEditTime: 2023-10-09 15:57:34
 * @Auditor:
 */
import { FormInstance } from 'rc-field-form/lib/interface';
import { ModalProps } from 'antd/lib/modal';

export type Type = 'block' | string;
export type DragSourceProps = 'menu' | 'canvas' | string;
export type DragDirectionProps = 'up' | 'down' | string;

export type ShowModalOptionsType = ModalProps & {
  form?: string;
  initValue?: any;
  hasDataList?: boolean; // datalist 需要启用body flex布局
  isFull?: boolean // 是否默认全屏
};

interface CurColumn extends Record<string, any> {
  dataIndex?: string;
  key?: string;
  title?: string;
  type?: string;
  width?: string;
}

export interface FdReducerProps {
  list: ControlProps[];
  modelListAndModelName?: string;
  hoverControlId?: string;
  formDesc?: string;
  formName?: string;
  dragDirection?: DragDirectionProps;
  dragSource?: DragSourceProps;
  curControl?: ControlProps;
  preview?: boolean;
  hideMenus?: boolean;
  noFormNameDesc?: boolean;
  tableCurrentController?: CurColumn;
  dataListCurrentController?: CurColumn;
}
export interface ActionProps extends Partial<FdReducerProps> {
  curColumn?: CurColumn | undefined;
  type?: string;
  modelListAndModelName?: string;
}
export interface StoreProps {
  state: FdReducerProps;
  dispatch(action: ActionProps): any;
}

export interface MenuProps {
  title: string;
  type: Type;
  icon: string;
}
export interface MenuGroupProps {
  title: string;
  children: MenuProps[];
}
export interface ControlProps {
  id: string;
  parentId?: string;
  name?: string;
  type: Type;
  children?: ControlProps[];
  options?: Record<string, any>;
  sourceForm?: string; // 通过insertForm添加时，标记字段来源form\
}
export type ControlRefProps = {
  getData?(source?: 'view'): any;
  onListRefresh?(): any;
  getDataNotCheck?(): any; // 获取数据不检验必填
  setData?(data: any): any; // 设置数据
  setTableRequired?(required: boolean | undefined, columnsRequired: Record<string, boolean>): any
};
export interface CanvasItemProps extends Record<string, any> {
  id?: string;
  _id?: string;
  domComplete?(dom: HTMLDivElement): void;
  isDesign?: boolean; // 设计模式
  validateFields?: Function; // 获取表单数据
  controlRefs?: Record<string, ControlRefProps>;
  getCurrInterceptors?(url: string): { get?: Function, set?: Function; };
  setActionFiledMap?(setFn: Function): void;
  setFieldsValue?(obj: any): void;
  showModal?(options: ShowModalOptionsType, changeId?: string): void;
  parentNext?(data: object): void;
}

export interface ViewProps {
  structure: {
    // 设计的结构
    list: ControlProps[];
    formName?: string;
    enviromentConfig?: any;
  };
  data?: Record<string, any>; // 填写的答案
  formInfo?: {
    formDesc?: string;
    formName?: string;
  }; // 填写的答案
  disabled?: boolean; // 禁用
  editFields?: string[]; // disabled 为true时，哪些字段可编辑
  hideFields?: string[]; // 隐藏字段
  onValuesChange?: (v1: any, v2: any) => void;
  formatFormBtns?: boolean;
  setFooter?: (v: { footer: React.ReactNode; }) => void;
  showPageHeaderBtn?: boolean;
  business?: any; // 业务注入信息
  parentNext?: (e: any) => void;
}

export interface ViewRefProps extends Omit<FormInstance, 'validateFields'> {
  validateFields(required?: boolean, options?: object): any;
}

export interface DesignRefProps {
  sync(list: ControlProps[]): void;
  getData(isExport?: boolean): { list: ControlProps[]; };
  changePreview(): void;
  setFormInfo(v: any): void;
}
export interface DesignProps {
  structure?: {
    list?: ControlProps[];
    modelListAndModelName?: string;
  };
  noFormNameDesc?: boolean; // 为true时 不显示填写formName 与 desc
  onChange?(state: FdReducerProps): void;
}


export interface InputProps extends Record<string, any> {
  modulesName: string;
  modulesUrl: string;
  serviceModuleCode: string;
  showFieldName: string;
  screenCondition?: any[];
  screenConditionRules?: any[];
  fieldNames: {
    value: string;
    label: string;
  }[];
}

export type NextResultType = {
  [k: string]: any;
};

export type ActionFieldType = Record<string, {
  disabled?: boolean;
  required?: boolean;
  hide?: boolean;
  hideExcludes?: string[];
  disabledExcludes?: string[];
  requiredExcludes?: string[];
}>;

export type EventsType = {
  on(eventName: string, callback: Function): void;
  trigger(eventName: string, data: any): void;
};

export type AppendFormChildConfigsType = {
  reset?: boolean;
  pre?: string;
  next?: Function;
};